﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Tools;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Formular
{
    class BuildingFormular
    {
        /** 获取建筑初始化等级 */
        public static int default_buildinglevel = 1;

        public static bool isNextBuildingDay(double lastdate)
        {
            double refreshdate = GlobalTimer.Instance.ToTimeSequence(DateTimeCoder.Instance.GetHeadOfToday()) + PlayerFormular.default_refresh_date;

            return SettingHelper.IsDailyRefresh(refreshdate, lastdate);
        }

        /// <summary>
        /// 建筑升级银币消耗
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        public static long getLevelupCashprice(Pixysoft.Weblications.Sango.Entities.Usr_Building building)
        {
            Entities.Cti_Building cityBuilding = CityBuildingHelper.searchBuilding(building.Buildingtypecode);

            long level = building.Buildinglevel + 1;

            return (long)Math.Round(cityBuilding.Cashvalue + cityBuilding.Increasecashvalue * level);
        }

        /// <summary>
        /// 建筑升级冷却时间
        /// </summary>
        /// <param name="building"></param>
        /// <param name="activity"></param>
        /// <returns></returns>
        public static long getLevelupCoolingTime(Pixysoft.Weblications.Sango.Entities.Usr_Building building, Entities.Usr_Activity activity)
        {
            Entities.Cti_Building cityBuilding = CityBuildingHelper.searchBuilding(building.Buildingtypecode);

            long level = building.Buildinglevel + 1;

            double timespan = DateTimeCoder.Instance.MinuteToMilliSecond((int)cityBuilding.Timevalue);

            return (long)Math.Round(timespan * (1 + level * 0.1 + activity.Buildingcount * 0.1));
        }

        /// <summary>
        /// 获取最大银币数目
        /// </summary>
        /// <returns></returns>
        public static long getMaxCacheValue(long level)
        {
            if (level < 10)
            {
                return 2000 + level * 500;
            }

            return 2000 + level * 500 + 1000 * level;
        }

        /// <summary>
        /// 取得资源上限
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static long getMaxResourceValue(long level)
        {
            if (level < 10)
            {
                return 2000 + level * 500;
            }

            return 2000 + level * 500 + 1000 * level;
        }

        /// <summary>
        /// 取得兵力上限
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static long getMaxSoldierValue(long level)
        {
            return 1000 + 500 * level;
        }
    }
}
